import java.util.Stack;

public class 括号验证 {
    public boolean isValid(String s){
        Stack<Character> stack =new Stack<>();
        for (char c : s.toCharArray()) {
            if(c == '(' || c=='{' ||c =='['){
                stack.push(c);
            }
            if (c == ')'){
                if (stack == null || stack.pop()!='('){
                   return  false;
                }
            }
            if (c == '}'){
                if (stack == null || stack.pop()!='{'){
                    return  false;
                }
            }
            if (c == ']'){
                if (stack == null || stack.pop()!='['){
                    return  false;
                }
            }
        }
         return  stack.isEmpty();
    }
}
